<link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL . '/media/skin/classic/share-to-social-networks.css?v=' . SKIN_VERSION ?>" />
<script type="text/javascript" src="<?php echo STATIC_URL .  "/media/vendor/tiny_mce/jquery.tinymce.js"?>"></script>
<!-- Facebook -->
<div class="facebook-share tooltip_label" title="<?php echo $this->translate('SN_F_SHARE');?>">
    <?php
        // Prevent cached by Facebook
        // Ref: http://tonymilne.com.au/posts/clear-cached-facebook-share-content
        $id = time().mt_rand(0, 9999);
        $url = $this->url.'/rep/'.$id;
        $url_facebook = $this->url_facebook.'/rep/'.$id;
    ?>
    <a onclick="Social.share.apply(this,[]);"
       data-href="<?php echo $url_facebook?>"
       data-ref="<?php echo $this->id_user?>"
       href="javascript:void(0)">
    </a>
</div>

<!-- Facebook invite friends -->
<?php
    $title = '';
    if ($this->is_contest) {
        $title = $this->translate('FB_RECOMMEND_TOOLTIP_CONTEST');
    } else {
        $title = $this->translate('FB_RECOMMEND_TOOLTIP_ENTRY');
    }
?>
<div class="facebook-invite-friends tooltip_label" title="<?php echo $title?>">
    <a class="fb_btn_recommend"
        onclick="Social.invite.apply(this,[]);"
        data-message="<?php echo $this->message /*Maximum: 60 characters; FB Rules*/?>"
        data-id-page="<?php echo $this->id_page ?>"
        data-id-object="<?php echo $this->id_object ?>"
        data-ref="<?php echo $this->id_user ?>"
        href="javascript:void(0)">
    </a>
</div>

<!-- Google Plus -->
<div class="googleplus-share tooltip_label" title="<?php echo $this->translate('SN_G_SHARE');?>">
    <?php $url = $this->url.'/id_user_ref/'.$this->id_user ?>
    <a href="https://plus.google.com/share?url=<?php echo $url ?>"
       onclick="javascript:window.open(this.href,
           '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
           return false;">
    </a>
</div>

<!-- Twitter -->
<div class="twitter-share tooltip_label" title="<?php echo $this->translate('SN_T_SHARE');?>">
    <?php
        // Ref: https://dev.twitter.com/docs/tweet-button
        $title = '';
        if (!empty($this->contest_name)) {
            $title = '"'.$this->contest_name.'" contest : ';
        }
        $title .= $this->title.' - ';
        $url = Core_Util::getBitlyUrl($this->url.'/id_user_ref/'.$this->id_user);
    ?>
    <a href="https://twitter.com/intent/tweet?original_referer=<?php echo urlencode($this->url)?>&text=<?php echo urlencode($title) ?>&tw_p=tweetbutton&url=<?php echo urlencode($url) ?>"
       data-count="none">
    </a>
    <script>!function(d,s,id){
        var js,fjs=d.getElementsByTagName(s)[0];
        if(!d.getElementById(id)){
            js=d.createElement(s);
            js.id=id;
            js.src="//platform.twitter.com/widgets.js";
            fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
</div>

<!-- LinkedIn -->
<div class="linkedin-share tooltip_label" title="<?php echo $this->translate('SN_L_SHARE');?>">
    <?php
        // Prevent cached by Facebook
        // @Ref: https://developer.linkedin.com/plugins
        $id = time() . mt_rand(0, 9999);
        $url = $this->url.'/id_user_ref/'.$this->id_user.'/rep/'.$id;
        $linkedin_url = "http://www.linkedin.com/shareArticle?mini=true&url=".urlencode($url);
    ?>
    <script>
        function lishare_click(url) {
            day = new Date();
            id = day.getTime();
            eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=0,width=610, height=460, left = 363, top = 144');");
        }
    </script>
    <a href="javascript:void(0)" onclick="lishare_click('<?php echo $linkedin_url?>'); return false;" target="_blank"></a>
</div>

<!-- Invites friends via email -->
<div class="email-invites tooltip_label" title="<?php echo $this->translate('SN_I_EMAIL');?>">
</div>

<?php
    $params = array(
        'url'  =>  $this->url_facebook.'/id_user_ref/'.$this->id_user,
        'title' => mysql_escape_string($this->title)
    );
    $subject = '';
    if ($this->is_contest) {
        $subject = $this->escape('%fb_name% invited you to %join% the '. $this->title);
    } else {
        $subject = $this->escape('%fb_name% invited you to %join% the '. $this->title.' entry of the '.$this->contest_name.' contest');
    }
    $message = array(
        'subject'   =>  $subject,
        'content'   => YouNet_Util::htmlToJs($this->partial('message-content.phtml', $params))
    );
?>
<script>
    $(document).ready(function(){
        $('.email-invites').invite_friends({
            'title': '<?php echo $this->translate('IF_TITLE_DIALOG')?>',
            'template': '<?php echo Core_Util::escapeForJS($this->partial('invite-friends.phtml', $message));?>',
            'url':  '<?php echo $this->invite_url ?>',
            'is_contest': '<?php echo $this->is_contest ?>',
            'content':  '<?php echo $message['content']?>'
        });
        $('.tooltip_label').tipsy({ gravity: $.fn.tipsy.autoBounds(50, 'n') });
    });
</script>